package com.service.business.member.controller;

import com.service.business.member.controller.rep.FeedbackDetailRep;
import com.service.business.member.controller.rep.FeedbackPageRep;
import com.service.business.member.controller.req.FeedbackPageReq;
import com.service.business.member.controller.req.FeedbackReq;
import com.service.business.framework.log.RequestLog;
import com.service.business.member.service.FeedbackService;
import com.service.business.support.SessionUtil;
import com.service.business.support.WxMsgUtil;
import com.service.core.rest.BaseController;
import com.service.core.rest.response.BaseResponse;
import com.service.core.rest.response.OneResponse;
import com.service.core.rest.response.PageResponse;
import com.service.dao.model.Feedback;
import com.service.utility.common.UUIDUtil;
import com.service.utility.modelmapper.ModelMapperUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 会员反馈表
 *
 * @author xxxx
 * @email xxxx@qq.com
 * @date 2019-11-11 09:26:11
 */
@Slf4j
@Api(tags = "会员反馈")
@RestController
@RequestMapping("feedback")
public class FeedbackController extends BaseController {
    @Autowired
    private FeedbackService feedbackService;

    @Autowired
    private SessionUtil sessionUtil;

    @Autowired
    private WxMsgUtil wxMsgUtil;

    @ApiOperation("反馈创建")
    @RequestLog("反馈创建")
    @PostMapping("create")
    public BaseResponse create(@RequestBody @Validated FeedbackReq feedbackReq) {
        String uuid = UUIDUtil.randomUUID();
        log.info("反馈创建 请求开始: 请求参数：{}，UUID:{}", feedbackReq, uuid);
        feedbackReq.setMemberId(sessionUtil.getUser().getUserId());
        feedbackService.create(feedbackReq);
        log.info("反馈创建 请求结束: UUID:{}", uuid);
//        wxMsgUtil.sendFTWxMsg("用户反馈","会员账号："+ feedbackReq.getMemberId()+"，反馈标题：" + feedbackReq.getFeedbackTitle());
        return successSaveBaseResponse();
    }

    @ApiOperation("分页查看反馈")
    @RequestLog("分页查看反馈")
    @PostMapping("page")
    public PageResponse<FeedbackPageRep> page(@RequestBody @Validated FeedbackPageReq pageReq) {
        pageReq.setMemberId(sessionUtil.getUser().getUserId());
        return successQueryPageResponse(feedbackService.pageFeedback(pageReq));
    }

    @ApiOperation("分页查看反馈")
    @RequestLog("分页查看反馈")
    @PostMapping("detail/{id}")
    public OneResponse<FeedbackDetailRep> detail(@PathVariable("id") Integer id) {
        return successQueryOneResponse(feedbackService.detail(id));
    }

}
